use std::fs;
use std::path::Path;
use chrono::Local;

pub fn backup_file<P: AsRef<Path>>(file_path: P) -> std::io::Result<()> {
    if file_path.as_ref().exists() {
        let timestamp = Local::now().format("%Y%m%d_%H%M%S");
        let backup_path = format!("{}.backup_{}",
                                  file_path.as_ref().to_string_lossy(),
                                  timestamp);

        fs::copy(file_path, backup_path)?;
    }
    Ok(())
}